package com.gxa.order.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.gxa.common.base.RespResult;
import com.gxa.order.dto.ServiceCommentsDTO;
import com.gxa.order.dto.ServiceUserProofDTO;
import com.gxa.order.entity.ServiceOrder;
import com.gxa.order.entity.ServiceUserProof;
import com.gxa.order.service.ServiceOrderAppService;
import com.gxa.order.service.ServiceOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Date;

@RestController
@RequestMapping("/serviceapporder")
public class ServiceOrderAppController {
    @Autowired
    private ServiceOrderAppService serviceOrderAppService;

    final Integer NO_STATUS=3;
    /**
     * 取消订单
     * @param orderid
     * @return
     */
    @RequestMapping("/cancel")
    public RespResult cancel(Integer orderid){
        UpdateWrapper<ServiceOrder> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",orderid).set("status",NO_STATUS).set("update_time",new Date());
        boolean update = serviceOrderAppService.update(updateWrapper);
        if (update){
          return   RespResult.success();
        }else {
            return RespResult.error("取消失败");
        }
    }

    /**
     * 上传图片
     * @param multipartFile
     * @param request
     * @return
     */
   @RequestMapping("/upload")
    public RespResult upload(MultipartFile[] multipartFile, HttpServletRequest request){
       RespResult upload = null;
       try {
           upload = serviceOrderAppService.upload(multipartFile, request);
       } catch (IOException e) {
           e.printStackTrace();
       }
       return  upload;
    }
    /**
     * 用户上传支付凭证
     * @param userProofDTO
     * @return
     */
    @RequestMapping("/uploadUserProof")
    public RespResult uploadUserProof(@RequestBody ServiceUserProofDTO userProofDTO){
        RespResult respResult = serviceOrderAppService.uploadProof(userProofDTO);
        return respResult;
    }
    /**
     * 用户进行评论
     * @param serviceCommentsDTO
     * @return
     */
    @RequestMapping("/comment")
    public  RespResult comment (@RequestBody ServiceCommentsDTO serviceCommentsDTO){
        RespResult comment = serviceOrderAppService.comment(serviceCommentsDTO);
        return RespResult.success();
    }

    /**
     * 查询所有订单
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/selectOrer")
    public RespResult  selectOrer(Integer page,Integer limit){
        RespResult respResult = serviceOrderAppService.orderAll();
        return  respResult;
    }


}
